package routines

import (
	"sdn-executor/utils/erros"
	"sdn-executor/utils/traces"
	"time"
)

// GoWithRecover 工具函数
func GoWithRecover(name string, f func()) {
	go func() {
		defer erros.Recover(name)
		f()
	}()
}

// GoWithTimeTrack 工具函数
func GoWithTimeTrack(name string, f func()) {
	go func() {
		defer traces.TrackTime(name, time.Now())
		f()
	}()
}

// GoWithRecoverWithTimeTrack 工具函数
func GoWithRecoverWithTimeTrack(name string, f func()) {
	go func() {
		defer erros.Recover(name)
		defer traces.TrackTime(name, time.Now())
		f()
	}()
}

// WrapWithRecover 工具函数
func WrapWithRecover(name string, f func()) func() {
	return func() {
		defer erros.Recover(name)
		f()
	}
}

// WrapWithTimeTrack 工具函数
func WrapWithTimeTrack(name string, f func()) func() {
	return func() {
		defer traces.TrackTime(name, time.Now())
		f()
	}
}

// WrapWithRecoverWithTimeTrack 工具函数
func WrapWithRecoverWithTimeTrack(name string, f func()) func() {
	return func() {
		defer erros.Recover(name)
		defer traces.TrackTime(name, time.Now())
		f()
	}
}
